// pages/comment/comment.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    stars: [0, 0, 0, 0, 0],
    score: 0,//
    files:[],
    focus:0,
    maxlength:200,
    remainLength: 200,
    addrname:'点击选择详细地址',
  },
  // 获取焦点事件
  focus:function(){
    this.setData({
      focus: 1 
    })
  },
  // 失去焦点事件
  blur:function(){
    this.setData({
      focus: 0
    })
  },
  // 便民信息
  getValue:function(e){
    var remark = e.detail.value
    var maxlength = this.data.maxlength
    console.log(remark)
    this.setData({
      remark:remark,
      remainLength: maxlength-remark.length
    })
  },
  // 选择地址
  getAddr:function(){
    var that = this
    wx.getLocation({
      success: function(res) {
        console.log(res)
       wx.chooseLocation({
         success: function(res) {
           console.log(res)
           that.setData({
             addrname:res.name,
             addrdetail: res.address
           })
         },
         fail: function(res) {},
         complete: function(res) {},
       })
      },
    })
  },
  // 手机号
  getPhone(e){
    var phone = e.detail.value
    this.setData({
      phone:phone
    })
  },
  summit:function(){
    var that = this
    wx.request({
      url: app.globalData.url+ 'zizhu',
      data:{
        content: that.data.remark,
        addr: that.data.addrdetail,
        tel: that.data.phone
      },
      success:function(res){
        console.log(res)
        wx.showToast({
          title: '发布成功',
          icon: 'success',
          duration: 2000,
          mask: true,
          success:function () {
            setTimeout(function(){
              wx.navigateBack({
                delta: 1,
              })
            },2000)
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})